<template>
  <view class="slides">
    <!-- 轮播图结构 -->
    <swiper circular="true" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
      <swiper-item v-for="(item,index) in swiperList" :key="index">
        <navigator :url="'/subpackaged/goods-detail/goods-detail?goods_id='  + item.goods_id" class="swiper-item"><image :src="item.image_src" mode=""></image></navigator>
        
      </swiper-item> 
    </swiper>
    <!-- 分类 -->
    <view class="navcontent">
       <view class="nav-item" @click="navClick(item)" v-for="(item,index) in navigation" :key="index">
         <image :src="item.image_src" mode="" class="nav-imgs" ></image>
       </view>
    </view>
    <!-- 层级 -->
    <view class="tier">
       <view class="tier-item" v-for=" (item,index) in stack" :key="index">
         <image :src="item.floor_title.image_src" class="floor_tit" mode=""></image>
         <view class="alltheimg">
            <view class="bigimg">
              <navigator class="imgleft" :url="item.product_list[0].url" >
                <image :style="{width: item.product_list[0].image_width + 'rpx'}" :src="item.product_list[0].image_src" mode="widthFix"></image>
              </navigator>
              <view class="imgright">
                <navigator class="rightlittle" v-for="(itemtow,two) in item.product_list" :key="two" :url="itemtow.url" >
                  <image v-if = "two !== 0"  :src="itemtow.image_src" mode="widthFix" :style="{width: itemtow.image_width + 'rpx'}" ></image>
                </navigator>
              </view>
            </view>
              
            </view>
         </view>
       </view>
    </view>

</template>

<script>

  export default {
    data() {
      return {
        //轮播图的数据列表
        swiperList:[],
        //分类导航的数据
        navigation:[],
        stack:[]
      };
    },
    onLoad() {
      //调用方法获取轮播图数据
      this.getSwipedata()
      this.getnavi()
      this.stackData()
    },
    methods:{
        
     async getSwipedata(){
      const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
       if(res.meta.status !== 200) return uni.$showthemes()
       this.swiperList = res.message
      // uni.$showthemes('数据加载成功了')
      },
     async getnavi(){
       const { data:res } = await uni.$http.get('/api/public/v1/home/catitems')
       if(res.meta.status !== 200) return uni.$showthemes()
       this.navigation = res.message
       console.log(this.navigation)
     },
     async stackData(){
       const { data:res } = await uni.$http.get('/api/public/v1/home/floordata')
       if(res.meta.status !== 200) return uni.$showthemes()
       this.stack = res.message
       //对数据进行处理 可以使用
       res.message.forEach(
        floor =>{
          floor.product_list.forEach( pro =>{
            //新添加一个属性url给他
            pro.url = '/subpackaged/goods-listdet/goods-listdet?' + pro.navigator_url.split('?')[1]
          })
        }
       )
       console.log(this.stack)
     },
     
     navClick(item){
       if(item.name === '分类'){
         uni.switchTab({
           url:'/pages/cate/cate'
         })
       }
     }
    },
  }
</script>

<style lang="scss">
 .slides{
   .navcontent{
     display:flex;
      justify-content:space-around;
      margin: 20rpx 0;
      .nav-imgs{
        width: 128rpx;
        height: 140rpx;
      }
         }
         .tier{    
           .tier-item{
             .floor_tit{
               width: 100%;
               height: 60rpx;
             }
             .alltheimg{
               
               .bigimg{
                 display: flex;
                 padding-left: 10rpx;
                 .imgright{
                   display: flex;
                   flex-wrap: wrap;
                   justify-content: space-around;
                 }
               }
             }
           }
         }
   swiper{
     height: 330rpx;
     
     .swiper-item{
       width: 100%;
       height: 100%;
            image{
         width: 100%;
         height: 100%;
       }
     }
   }
 }
</style>
